import Vue from 'vue';
import Router from 'vue-router';
import routes from './routes';

Vue.use(Router);
// 解决路由重复跳转时的报错问题
const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err);
};
const originalReplace = Router.prototype.replace;
Router.prototype.replace = function replace(location) {
    return originalReplace.call(this, location).catch(err => err);
};

const router = new Router({
    base: process.env.BASE_PUBLIC ? process.env.BASE_PUBLIC : '/',
    mode: process.env.ROUTER_MODE === 'history' ? 'history' : 'hash',
    routes,
});

export default router;
